package com.cloxtec.scada.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.cloxtec.scada.utils.*;
import com.mongodb.BasicDBObject;
import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.Invocable;

/*
1、本类用于存储当前实时数据，是个全局类
2、定时计算任务后的数据，也实时刷新本类中的数据
3、所有的数据都有两种存储方式：一级扁平结构的key-value；二层key-value结构，第二级的key-value，是属性和值
*/

@Component
@Slf4j
public class RealTimeData {

    @Resource
    private MongoHelper mongoHelper;

    @Resource
    private LogHelper logHelper;

    @Resource
    private MqttPubClient mqttPubClient;

    @Resource
    private ParamHelper paramHelper;

    @Resource
    private ScheduledTaskManager scheduledTaskManager;


    public void init() {
        Timer heartbeatTimer = new Timer();
        heartbeatTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    broadcastOnlineInfo();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, 5000, 5000);//5秒后开始， 1 分钟启动一次，刷新设备在线状态
    }


    private void broadcastOnlineInfo() {

    }


}
